//
//  MKLoginInputView.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/13.
//  Copyright © 2017年 cc.moko. All rights reserved.
//

import UIKit
//enum MKLoginInputViewType {
//    case account
//    case password
//}
class MKLoginInputView: UIView {

    var sign:UIImageView!
    var vlineOne:UIView!
    var textFiled:UITextField!
    var eye:UIButton!
    var vLineTwo:UIView!
    var clear:UIButton!
    var hLine:UIView!
    var type:String!
    
    var isAccount:Bool!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.sign = UIImageView.init()
        self.addSubview(self.sign)
        
        self.vlineOne = UIView.init()
        self.vlineOne.backgroundColor = UIColorFromRGB(rgbValue: 0xe5e5e5, A: 1)
        self.addSubview(self.vlineOne)
        
        self.textFiled = UITextField.init()
        self.textFiled.font = fonts(size: 16)
        self.textFiled.keyboardType = .default;
        self.textFiled.clipsToBounds = true
        self.addSubview(self.textFiled)
        
        self.eye = UIButton.init()
        self.eye.addTarget(self, action: #selector(eyeClick), for: .touchUpInside)
        self.eye.setImage(UIImage.init(named: "MK_RegisterDeng-AnWen"), for: .normal)
        self.addSubview(self.eye)
        
        self.vLineTwo = UIView.init()
        self.vLineTwo.backgroundColor = UIColorFromRGB(rgbValue: 0xe5e5e5, A: 1)
        self.addSubview(self.vLineTwo)
        
        self.clear = UIButton.init()
        self.clear.setImage(UIImage.init(named: "MK_RegisterDeng-QuXiao"), for: .normal)
        self.clear.addTarget(self, action: #selector(clearClick), for: .touchUpInside)
        self.addSubview(self.clear)
        
        self.hLine = UIView.init()
        self.hLine.backgroundColor = UIColorFromRGB(rgbValue: 0xe5e5e5, A: 1)
        self.addSubview(self.hLine)
        
        self.config(type: false)
    }
    func clearClick() -> Void {
        self.textFiled.text = ""
        print("clearClick")
    }
    func eyeClick() -> Void {
        print("eyeClick")
        self.textFiled.isSecureTextEntry = !self.textFiled.isSecureTextEntry
        if(self.textFiled.isSecureTextEntry){
            self.eye.setImage(UIImage.init(named: "MK_RegisterDeng-AnWen"), for: .normal)
        }else{
            self.eye.setImage(UIImage.init(named: "MK_RegisterDeng-MingWen"), for: .normal)
        }
    }
    func config(type:Bool) -> Void {
        self.isAccount = type
        self.setNeedsLayout()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.sign.frame = CGRect.init(x: 15, y: (self.height - 22.5) * 0.5, width: 22.5, height: 22.5)
        self.vlineOne.frame = CGRect.init(x: self.sign.right + 12, y: (self.height - 28) * 0.5, width: 0.5, height: 28)

        if(self.isAccount){
            self.sign.image = UIImage.init(named: "MK_RegisterDengZhangHao")
            self.eye.frame = CGRect.init(x: self.width - 107, y: 0, width: 56.5, height: self.height - 0.5)
            self.vLineTwo.frame = CGRect.init(x: self.eye.right, y: (self.height - 28) * 0.5, width: 0.5, height: 28)
            self.clear.frame = CGRect.init(x: self.vLineTwo.right, y: 0, width: 50, height: self.height - 0.5)
            self.textFiled.frame = CGRect.init(x: self.vlineOne.right + 12, y: 0, width: self.width - (self.vlineOne.right + 12) - 107, height: self.height - 0.5)
        }
        else{
            self.sign.image = UIImage.init(named: "MK_RegisterDeng-Passwd")
            self.eye.frame = CGRect.zero
            self.vLineTwo.frame = CGRect.init(x: self.width - 50.5, y: (self.height - 28) * 0.5, width: 0.5, height: 28)
            self.clear.frame = CGRect.init(x: self.vLineTwo.right, y: 0, width: 50, height: self.height - 0.5)
            self.textFiled.frame = CGRect.init(x: self.vlineOne.right + 12, y: 0, width: self.width - (self.vlineOne.right + 12) - 50.5, height: self.height - 0.5)
        }
        self.hLine.frame = CGRect.init(x: 0, y: self.height - 0.5, width: self.width, height: 0.5)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
